package com.lifesea.system.api;

import com.github.pagehelper.PageInfo;
import com.lifesea.base.entity.PagingRequest;
import com.lifesea.commons.exception.ErrorCodeException;
import com.lifesea.model.SysLog;
import com.lifesea.system.api.service.SysLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 日志方法实现
 *
 */
@Service("logApi")
public class LogApiImpl implements LogApi {

    private final Logger logger = LoggerFactory.getLogger(LogApiImpl.class);


    @Autowired
    private SysLogService logService;

    @Override
    public PageInfo<SysLog> getPage(PagingRequest pagingRequest, Map conditionBean) throws ErrorCodeException {
        return logService.pageList(pagingRequest,conditionBean);
    }

    @Override
    public SysLog get(Long pkId) throws ErrorCodeException {
        return logService.findOne(pkId);
    }

    @Override
    public List<SysLog> get(Map conditionBean) throws ErrorCodeException {
        return logService.find(conditionBean);
    }

    @Override
    public int save(SysLog record) throws ErrorCodeException {
        return logService.save(record);
    }

    @Override
    public int saveGeneratedKeys(SysLog record) throws ErrorCodeException {
        return logService.saveGeneratedKeys(record);
    }

    /**
     * 插入并且更新日志号
     * @param record
     * @return
     * @throws ErrorCodeException
     */
    @Override
    public boolean insertLog(SysLog record) throws ErrorCodeException {
        save(record);
        record.setLogNumber(record.getId()+100000);
        updateByPrimary(record);
        return true;
    }

    @Override
    public int updateByPrimary(SysLog record) throws ErrorCodeException {
        return logService.update(record);
    }

    @Override
    public int delete(Long pkId) throws ErrorCodeException {
        return logService.delete(pkId);
    }
}
